package com.example.myadmin.common.vo;


import lombok.Data;

/**
 * LayUi要求的数据
 * @param <T>
 */

@Data
public class Result<T> {
    private Integer code; //返回码 0表示成功
    private String message; //返回描述
//    private Object data;
    private T data;  //返回数据(防止Object强转，加上泛型)
    private Long count;  //分页查询的总记录数


    //由于提供了公共的静态方法，为了让其他方法不去new对象，手动生成私有的构造方法
    private Result(Integer code, String message, T data, Long count) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.count = count;
    }

    private Result() {
    }

    public static Result<Object> success(){
       return new Result<>(0, "success", null, null);

    }
    public static Result<Object> success(String message){
        return new Result<>(0, message, null, null);

    }

    public static Result<Object> success(Object data,Long count){
        return new Result<>(0, "success", data, count);

    }

    public static Result<Object> fail(){
        return new Result<>(-1, "fail", null, null);
    }
    public static Result<Object> fail(String message){
        return new Result<>(-1, message, null, null);
    }
}
